import datetime

from django.contrib import admin
from django.db import models

# Create your models here.
from django.utils import timezone


class ShareInfo(models.Model):
    share_title = models.CharField(max_length=300)
    share_id = models.CharField(max_length=50)
    share_user = models.CharField(max_length=100)
    share_date = models.DateTimeField("date shared", null=True, default=None, blank=True)
    updated_at = models.DateTimeField("date updated", null=True, default=None, blank=True)
    share_num = models.IntegerField(default=0)
    share_lang = models.IntegerField(default=1)

    def __str__(self):
        return self.share_title

    @admin.display(
        boolean=True,
        ordering="share_date",
        description="Shared recently?",
    )
    def was_shared_recently(self):
        now = timezone.now()
        if self.share_date:
            # return now - datetime.timedelta(days=1) <= self.share_date <= now
            return now - datetime.timedelta(hours=20, minutes=59, seconds=59) <= self.share_date <= now
        else:
            return False
